(function() {
	var $ = require(L('$')), _ = require(L('_'));

	var win = $.createWindow(L('win_setting'));
	var ui = $.layout('setting');
	win.add([$.ui('navbar')(false, false), ui.view]);

	ui.group1.add(SettingButton(L('title_how_it_work'), L('code_how_it_work')));
	ui.group1.add(SettingButton(L('title_who_involved'), L('code_who_involved')));
	ui.group1.add(SettingButton(L('title_privacy_policy'), L('code_privacy_policy')));
	ui.group1.add(SettingButton(L('title_security_policy'), L('code_security_policy')));
	ui.group1.add(SettingButton(L('title_terms_and_conditions'), L('code_terms_and_conditions')));
	ui.group2.add(SettingButton(L('title_contact_us'), null, L('url_website'), null));
	ui.group2.add(SettingButton(L('title_ask_question'), null, null, $.enquiriesEmail()));
	ui.group2.add(SettingButton(L('title_faq'), L('code_faq')));
	ui.switcher.value = $.allowReceiveNotification();
	$.on('change', ui.switcher, function() {
		$.webservice().updateMobileAppSetting(ui.switcher.value, function() {
			$.allowReceiveNotification(ui.switcher.value)
		});
	});

	function SettingButton(text, code, url, email) {
		var label = Ti.UI.createLabel({
			backgroundImage : L('bg_arrow_right'),
			width : 280,
			height : 40,
			color : L('color_gray'),
			text : '  ' + text,
			top : 8,
			font : {
				fontFamily : L('font_default')
			}
		});
		$.tap(label, function() {
			$.w('code = ' + code)
			if (!$.isNull(code)) {
				$.win('setting_details').update(code, true, null);
				$.win('my_account').nav.push($.win('setting_details'));
			} else if (!$.isNull(url)) {
				Ti.Platform.openURL(url);
			} else if (!$.isNull(email)) {
				$.mailTo(email);
			}
		});
		return label;
	};

	module.exports = win;
})();
